package com.servlet;

import java.io.IOException;
import java.io.Writer;
import java.util.Enumeration;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/ParameterDemo")
public class ParameterDemo extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public ParameterDemo() {
    	
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
//		String name = request.getHeader("Accept");
//		System.out.println(name);
		
		//如果获取请求参数值出现乱码，就要设置请求参数的编码。
		request.setCharacterEncoding("utf-8");	
		response.setCharacterEncoding("utf-8");	
		response.setContentType("text/html");	//文档类型
		
		String name=request.getParameter("name");
		String psw=request.getParameter("password");
		
//		Enumeration<String> headers=request.getHeaderNames();
//		Writer out=response.getWriter();
//		out.write("<table border='1'>");
//		while(headers.hasMoreElements()){
//			String str=headers.nextElement();
//			String ss=request.getHeader(str);	
//			out.write("<tr><td>"+str+"</td><td>"+ss+"</td></tr>");
//		}
//		out.write("</table>");
		
		ServletContext application=request.getServletContext();
		String nameApplication=new String(application.getAttribute("name").toString().getBytes("ISO-8859-1"), "UTF-8");
		System.out.println(nameApplication);
//		System.out.println(nameApplication);
//		
//		System.out.println();
		
//		String con=request.getHeader("Content-Type");
//		Writer out1=response.getWriter();
//		out1.write("<table border='1'><tr><td>"+nameApplication+ "</td></tr></table>");	
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
